//
//  PlayView.m
//  27-block播放按钮
//
//  Created by dllo on 16/8/19.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "PlayView.h"
#import "UIView+Frame.h"
#define width self.bounds.size.width
#define height self.bounds.size.height

@interface PlayView ()
@property (nonatomic,copy) void (^play)(UIButton *play);
@property (nonatomic,copy) void (^pause)(UIButton *pause);
@end

@implementation PlayView

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setUp];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}


- (void)setUp
{
    _button0 = [UIButton buttonWithType:UIButtonTypeCustom];
//    _button0.backgroundColor = [UIColor yellowColor];
    [self addSubview:_button0];
    _button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_button1];
    _button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_button2];
    
}

- (void)layoutSubviews
{
    
    [super layoutSubviews];
    _button0.frame = CGRectMake(0, 0, 100, 100);
    _button0.center = CGPointMake(width / 2, height / 2);
    [_button0 setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    [_button0 addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
//    _button1.frame = CGRectMake(0, 0, 60, 60);
    _button1.sy_width = 60;
    _button1.sy_height = 60;
    _button1.sy_centerY = _button0.sy_centerY;
    
    _button1.sy_centerX = _button0.sy_centerX - _button1.sy_width / 2 + _button0.sy_width / 2 + 60;
    [_button1 setImage:[UIImage imageNamed:@"2"] forState:UIControlStateNormal];
    
    
    _button2.sy_width = 60;
    _button2.sy_height = 60;
    _button2.sy_centerY = _button0.sy_centerY;
    
    _button2.sy_centerX = _button0.sy_centerX + _button1.sy_width / 2 + _button0.sy_width / 2 + 60;
    [_button2 setImage:[UIImage imageNamed:@"3"] forState:UIControlStateNormal];
    
    
//    _button2.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)
}

- (UIButton *)buttonImageWithName:(NSString *)imageName action:(SEL)action
{
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    return button;
}

- (void)play:(UIButton *)playButton
{
    [playButton setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    [playButton removeTarget:self action:@selector(pause:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)pause:(UIButton *)pauseButton
{
    self.play(pauseButton);
}

- (void)play:(void (^)(UIButton *))play pause:(void (^)(UIButton *))pause
{
    _play = play;
    _pause = pause;
}











@end
